import request from '@/config/axios'

export interface EvalSchemeVO {
  id?: number
  schemeCode: string
  schemeName: string
  professionCode: string
  professionName: string
  applicableLevels: string
  evaluationMethod: string
  schemeContent: string
  schemeVersion: string
  schemeStatus: number
  isDefault: boolean
  schemeComments?: string
  createTime?: Date
}

export interface EvalSchemeTemplateRelationVO {
  id?: number
  schemeId: number
  templateId: number
  templateWeight: number
  templateOrder: number
  relationStatus: number
  createTime?: Date
}

export interface EvalSchemePageReqVO extends PageParam {
  schemeCode?: string
  schemeName?: string
  professionCode?: string
  professionName?: string
  evaluationMethod?: string
  schemeStatus?: number
  isDefault?: boolean
  createTime?: Date[]
}

export interface EvalSchemeTemplateRelationPageReqVO extends PageParam {
  schemeId?: number
  templateId?: number
  relationStatus?: number
  createTime?: Date[]
}

// 评价方案相关API
export const getSchemePage = (params: EvalSchemePageReqVO) => {
  return request.get({ url: '/eval/scheme/page', params })
}

export const getScheme = (id: number) => {
  return request.get({ url: '/eval/scheme/get?id=' + id })
}

export const createScheme = (data: EvalSchemeVO) => {
  return request.post({ url: '/eval/scheme/create', data })
}

export const updateScheme = (data: EvalSchemeVO) => {
  return request.put({ url: '/eval/scheme/update', data })
}

export const deleteScheme = (id: number) => {
  return request.delete({ url: '/eval/scheme/delete?id=' + id })
}

export const exportScheme = (params: EvalSchemePageReqVO) => {
  return request.download({ url: '/eval/scheme/export-excel', params })
}

export const getSchemeListByProfessionCode = (professionCode: string) => {
  return request.get({ url: '/eval/scheme/list-by-profession?professionCode=' + professionCode })
}

export const getSchemeListByEvaluationMethod = (evaluationMethod: string) => {
  return request.get({ url: '/eval/scheme/list-by-method?evaluationMethod=' + evaluationMethod })
}

export const getSchemeListByStatus = (schemeStatus: number) => {
  return request.get({ url: '/eval/scheme/list-by-status?schemeStatus=' + schemeStatus })
}

export const getDefaultSchemeList = () => {
  return request.get({ url: '/eval/scheme/default-list' })
}

export const publishScheme = (id: number) => {
  return request.put({ url: '/eval/scheme/publish?id=' + id })
}

export const disableScheme = (id: number) => {
  return request.put({ url: '/eval/scheme/disable?id=' + id })
}

export const setDefaultScheme = (id: number) => {
  return request.put({ url: '/eval/scheme/set-default?id=' + id })
}

export const copyScheme = (id: number, newSchemeName: string) => {
  return request.post({ url: '/eval/scheme/copy', data: { id, newSchemeName } })
}

// 方案模板关联相关API
export const getSchemeTemplateRelationPage = (params: EvalSchemeTemplateRelationPageReqVO) => {
  return request.get({ url: '/eval/scheme-template-relation/page', params })
}

export const getSchemeTemplateRelation = (id: number) => {
  return request.get({ url: '/eval/scheme-template-relation/get?id=' + id })
}

export const createSchemeTemplateRelation = (data: EvalSchemeTemplateRelationVO) => {
  return request.post({ url: '/eval/scheme-template-relation/create', data })
}

export const updateSchemeTemplateRelation = (data: EvalSchemeTemplateRelationVO) => {
  return request.put({ url: '/eval/scheme-template-relation/update', data })
}

export const deleteSchemeTemplateRelation = (id: number) => {
  return request.delete({ url: '/eval/scheme-template-relation/delete?id=' + id })
}

export const getSchemeTemplateRelationListBySchemeId = (schemeId: number) => {
  return request.get({ url: '/eval/scheme-template-relation/list-by-scheme?schemeId=' + schemeId })
}

export const getSchemeTemplateRelationListByTemplateId = (templateId: number) => {
  return request.get({ url: '/eval/scheme-template-relation/list-by-template?templateId=' + templateId })
}

export const batchCreateSchemeTemplateRelation = (schemeId: number, templateRelations: any[]) => {
  return request.post({ url: '/eval/scheme-template-relation/batch-create', data: { schemeId, templateRelations } })
}

export const updateSchemeTemplateRelationOrder = (relations: { id: number; templateOrder: number }[]) => {
  return request.put({ url: '/eval/scheme-template-relation/update-order', data: { relations } })
}
